package com.qf.service.impl;

import com.qf.mapper.ProjectMapper;
import com.qf.mapper.StageMapper;
import com.qf.mapper.TaskplanMapper;
import com.qf.model.Stage;
import com.qf.model.Taskplan;
import com.qf.page.PageResult;
import com.qf.page.QueryPageBean;
import com.qf.service.StageService;
import com.qf.service.TaskplanService;
import com.qf.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class TaskplanServiceImpl implements TaskplanService {
    @Autowired
    private TaskplanMapper taskplanMapper;
    @Autowired
    private ProjectMapper projectMapper;
    //分页查询+模糊查询
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer CurrentPage = queryPageBean.getCurrentPage();
        Integer PageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageResult pageResult = new PageResult();
        //当前页结果
        List<Taskplan> rows = taskplanMapper.findPage((CurrentPage-1)*PageSize, PageSize,queryString);
        //总记录数
        Long count = taskplanMapper.count(queryString);
        pageResult.setTotal(count);
        pageResult.setRows(rows);
        return pageResult;
    }

    //新建开发商并绑定工程
    @Override
    @Transactional
    public boolean add(Taskplan taskplan) {
        taskplan.setUpdatetime(new Date());
        taskplan.setTid(UUIDUtils.uuid());
        //新增stage
        int i = taskplanMapper.addOne(taskplan);
        if (i>0){
            return true;
        }
        return false;
    }


    //根据sid查询stage回显
    @Override
    public Taskplan findById(String sid) {
        Taskplan taskplan = taskplanMapper.findById(sid);

        return taskplan;
    }

    //修改developer
    @Override
    @Transactional
    public int edit(Taskplan taskplan) {
        taskplan.setUpdatetime(new Date());
        //修改developer
        int i = taskplanMapper.editOne(taskplan);
        return i;
    }

    //删除stage
    @Override
    @Transactional
    public int delete(String tid) {
        int i = taskplanMapper.delete(tid);
        return i;
    }
}
